package com.itheima.jdbc.lianxi;

import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;
import java.net.DatagramSocket;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ResourceBundle;

public class 连接池 {
  private  static DataSource dataSource;
        // 创建连接池
    static {
            DruidDataSource dataSource1=new DruidDataSource();
            ResourceBundle bundle = ResourceBundle.getBundle("jdbc");
            dataSource1.setDriverClassName(bundle.getString("jdbc.driverClassName"));
            dataSource1.setUrl(bundle.getString("jdbc.url"));
            dataSource1.setUsername(bundle.getString("jdbc.username"));
            dataSource1.setPassword(bundle.getString("jdbc.password"));
            //连接池中 最大个数
            dataSource1.setMaxActive(8);
            //最大等待时间
            dataSource1.setMaxWait(2000);
            //连接池中 空闲时间内容 销毁无用连接 最小留下
            dataSource1.setMinIdle(8);
            dataSource=dataSource1;
    }

    public static Connection getConnection() throws SQLException {
        return  dataSource.getConnection();
    }
}
